#pragma once
#ifndef __LIT__SCRIPT__PREPROCESSOR__HH__
#define __LIT__SCRIPT__PREPROCESSOR__HH__

#include <OgreString.h>
#include <LitFilePath.h>
#include <boost\function.hpp>
#include <boost\bind.hpp>
#include <LitExceptions.h>

namespace Lit
{
	class ScriptPreprocessor
	{
	public:

		static const std::string Win32Endl;
		static const std::string UnixEndl;
		static const std::string OSXEndl;

		struct Section
		{
			Section( const Section& rk );
			Section( const std::string &nam, const std::string &str, const size_t line_offset_ = 0 );

			std::string join( const std::string &link = ScriptPreprocessor::Win32Endl ) const;
			size_t numLines( ) const;

			std::vector<std::string> d;
			std::string name;
			size_t		line_offset;
		};
		
		typedef boost::function<bool(const FilePath&)> IncludeCallbackType;
		typedef boost::function<void(const std::string&, const std::string & )> DefineCallbackType;
	protected:
		DefineCallbackType mDefine;
		IncludeCallbackType mInclude;
		
		static bool _dummy_include( const FilePath& path );
		static void _dummy_define( const std::string&name, const std::string &value );

	public:
		ScriptPreprocessor();
		virtual ~ScriptPreprocessor();
				
		void setIncludeCallback( IncludeCallbackType cbk );
		void setDefineCallback( DefineCallbackType cbk );

		ScriptPreprocessor::Section stripComments( const ScriptPreprocessor::Section & section );

		void setDefaultIncludeCallback( );
		void setDefaultDefineCallback( );

		void processDirective( const std::string &unit_name, const std::string &line, size_t line_id );
		void processScriptSection( Section & section );
	};
};

#endif